package com.qf.test;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class Demo3 {
    @Test
    public void testJsonSet(){

    }
    @Test
    public void testJsonGet(){

    }
    @Test
    public void testPool(){
        //1创建连接池配置信息对象
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        //最大连接数
        config.setMaxTotal(50);
        //最大空闲数
        config.setMaxIdle(10);
        //最小空闲数
        config.setMinIdle(5);
        //超时时间，也就是多久不用连接 连接超时
        config.setMaxWaitMillis(3000);
        //2创建连接池
        JedisPool jedisPool = new JedisPool(config, "192.168.200.129", 6379);
        //3通过连接池获取jedis对象
        Jedis jedis = jedisPool.getResource();
        //4获取redis中的数据
        String key1 = jedis.get("key1");
        System.out.println("======="+key1);

        //5释放资源
        jedis.close();



    }
        @Test
        public void testPipeLine(){
            JedisPool jedisPool = new JedisPool("192.168.200.129", 6379);
            long current = System.currentTimeMillis();
            Jedis jedis = jedisPool.getResource();
            for (int i = 0;i <= 10000; i++){
                jedis.incr("key1");
            }
            jedis.close();
            System.out.println(System.currentTimeMillis()-current);
        }


}
